top command
top
- display Linux processes
The top
command in Linux is a real-time system monitoring tool that displays running processes, CPU, memory, and other system stats. It’s interactive, allowing you to sort, filter, or kill processes directly.
Usage: top [options]
options
: Flags to customize startup behavior (optional).- Runs interactively by default—exit with
q
.
Common Fields Explained
Column | Description |
---|---|
PID | Process ID |
USER | Process owner |
%CPU | CPU usage percentage |
%MEM | Memory usage percentage |
VIRT | Virtual memory used |
RES | Resident (physical) memory used |
S | State (R=running, S=sleeping, Z=zombie) |
TIME+ | Total CPU time used |
COMMAND | Command that started the process |
Examples
-
Basic Usage
Run
top
to see a live view of system processes.top
-
Output (example):
top - 10:00:00 up 1 day, 2:00, 2 users, load average: 0.15, 0.20, 0.25
Tasks: 123 total, 1 running, 122 sleeping, 0 stopped, 0 zombie
%Cpu(s): 5.0 us, 2.0 sy, 0.0 ni, 92.0 id, 0.5 wa, 0.0 hi, 0.5 si, 0.0 st
MiB Mem : 8192.0 total, 4096.0 free, 3072.0 used, 1024.0 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 alice 20 0 500m 200m 100m S 2.0 2.4 0:10.00 firefox
1 root 20 0 100m 10m 5m S 0.0 0.1 0:05.00 systemd -
Top Section: System summary (uptime, load, CPU, memory).
-
Bottom Section: Process list (PID, user, CPU/memory usage, command).
-
-
Navigation and Interaction
top
is interactive—use these keys:Key Action q
Quit top
Space
Refresh now h
or?
Show help k
Kill a process (enter PID) f
Manage fields (add/remove columns) Shift + P
Sort by CPU usage (default) Shift + M
Sort by memory usage u
Filter by user (enter username) Example (Kill):
- Press
k
, enter PID (e.g.,1234
), pressEnter
, choose signal (default15
forSIGTERM
).
- Press
-
Customizing Display
Adjust what you see in real time.
Change Refresh Rate:
Press
d
, enter seconds (e.g.,1
for 1-second updates).Filter by User:
Press
u
, typealice
, pressEnter
—shows onlyalice
’s processes.Add Fields:
Press
f
, navigate with arrows, toggle columns (e.g.,%MEM
), pressq
to save. -
Starting with Options
Launch
top
with specific settings.Example (User Filter):
top -u alice
- Shows only
alice
’s processes.
Example (PID Focus):
top -p 1234
- Monitors only PID 1234.
Example (Batch Mode):
top -b -n 1
- Runs once (
-n 1
) in batch mode (-b
), outputs to terminal (useful for scripts).
- Shows only
For more details, check the manual with man top